<?php
//=======================================
//###################################
// Kayako Web Solutions
//
// Source Copyright 2001-2004 Kayako Web Solutions
// Unauthorized reproduction is not allowed
// License Number: $%LICENSE%$
// $Author: vshoor $ ($Date: 2005/05/26 22:02:02 $)
// $RCSfile: client_changepassword.php,v $ : $Revision: 1.2 $ 
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
//###################################
//=======================================

if (!defined("INSWIFT")) {
	trigger_error("Unable to process $PHP_SELF", E_USER_ERROR);
}

require_once ("./includes/functions_users.php");
require_once ("./includes/functions_html.php");
$template->loadLanguageSection("changepassword");

$template->assign("navigation", '<a href="index.php" id="navlink">'.$_SWIFT["language"]["navhome"].'</a> &raquo; <a href="index.php?_m=core&_a=changepassword" id="navlink">'.$_SWIFT["language"]["changepassword"]."</a>");

/**
* ###############################################
* CHANGE THE PASSWORD
* ###############################################
*/
if ($_POST["step"] == "1")
{
	if (trim($_POST["oldpassword"]) == "" || trim($_POST["newpassword"]) == "" || trim($_POST["newpasswordc"]) == "")
	{
		$template->assign("posterror", true);
		$template->assign("errormessage", $_SWIFT["language"]["requiredfieldempty"]);
		unset($_POST["step"]);
	} else if (trim($_POST["newpassword"]) != trim($_POST["newpasswordc"])) {
		$template->assign("posterror", true);
		$template->assign("errormessage", $_SWIFT["language"]["changepmatcherr"]);
		unset($_POST["step"]);
	} else {
		// All Ok. Load the User Password
		$_user = $dbCore->queryFetch("SELECT * FROM `". TABLE_PREFIX ."users` WHERE `userid` = '". intval($_SWIFT["user"]["userid"]) ."';");
		if (empty($_user["userid"]) || $_user["userpasswordtxt"] != $_POST["oldpassword"])
		{
			$template->assign("posterror", true);
			$template->assign("errormessage", $_SWIFT["language"]["changeperror"]);
			unset($_POST["step"]);
		} else {
			// Change the Password!
			changeUserPassword($_SWIFT["user"]["userid"], $_POST["newpassword"]);
			$template->assign("backurl", "index.php");
			$template->assign("sectiontitle", $_SWIFT["language"]["changepassword"]);
			$template->assign("sectiondesc", $_SWIFT["language"]["changepsuccess"]);
			echo $template->displayTemplate("changepasswordconfirm");
		}
	}




/**
* ###############################################
* DISPLAY THE CHANGE PASSWORD FORM
* ###############################################
*/
}

if (empty($_POST["step"]))
{
	$template->cache(array('changepassword', 'header', 'footer', 'navbar'));
	$template->assign("backurl", "index.php");
	$template->assign("sectiontitle", $_SWIFT["language"]["changepassword"]);
	$template->assign("sectiondesc", $_SWIFT["language"]["changepdesc"]);
	$template->assign("oldpassword", $_POST["oldpassword"]);
	$template->assign("newpassword", $_POST["newpassword"]);
	$template->assign("newpasswordc", $_POST["newpasswordc"]);
	echo $template->displayTemplate("changepassword");
}
?>